import sys
import webbrowser
import tempfile
from Common import CommonHelper as cm
from datetime import datetime
from tkinter import messagebox


def check_expire():
    # 获取打包日期
    package_date = datetime.strptime(cm.get_config('Expire', 'PackageDate'), '%Y-%m-%d')
    # 获取有效期
    expire_day = int(cm.get_config('Expire', 'ExpireDay'))
    # 获取当前日期
    current_date = datetime.now()
    return (current_date - package_date).days > expire_day

def create_temp_html_file():
    html_file = open(cm.get_path('test.html'), 'r', encoding='utf-8')
    html_str = html_file.read()
    with tempfile.NamedTemporaryFile(mode='w', suffix='.html', encoding='utf-8', delete=False) as f:
        f.write(html_str)
        return f.name



if check_expire():
    messagebox.showinfo("提示", "该程序已过有效期，请联系管理员....")
    sys.exit()
else:
    file_path = create_temp_html_file()
    webbrowser.open('file://' + file_path)


